<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    账号：<input type="text">
    账号：<input type="text">
    验证码：<input type="text">
    <button id="code">1134</button>
    <button id="login">登录</button>
    <script>
        code.onclick = function() {
            code.innerHTML = parseInt(Math.random() * 9000 + 1000)
        }
        login.onclick = function() {
            var num = document.getElementsByTagName('input')[2]
            if (num.value == code.innerHTML) {
                alert('登录成功')
            } else {
                alert('验证码错误')
                num.value = ''
                code.innerHTML = parseInt(Math.random() * 9000 + 1000)
            }
        }
    </script>
</body>

</html>